package DCSource.Size.Template;

import java.util.ArrayList;

public class Size {
	private double value;
	private double index;
	private ArrayList<Double> power = new ArrayList<Double>();
	public Size(double value, double index){
		this.value = value;
		this.index = index;
	}
	private double nSqrt(double x, double n) {
		   return Math.pow(x, (double) 1/n);
	}
	public double getValue(){
		return value;
	}
	public double getIndex(){
		return index;
	}
	public void setValue(double value){
		this.value = value;
	}
	public void setIndex(double index){
		this.index = index;
	}
	public void add(double value){
		this.value+=value;
	}
	public void multi(double value){
		this.value*=value;
	}
	public void sub(double value){
		this.value-=value;
	}
	public void div(double value){
		this.value/=value;
	}
	public void pow(double value){
		this.value=Math.pow(this.value,value);
		this.power.add(value);
	}
	public void addPower(double value){
		this.power.add(value);
	}
	public void removeLastPower(){
		if (this.power.size()>0){
			this.power.remove(this.power.size()-1);
		}
	}
	public void removePower(){
		this.power.clear();
	}
	public void undoPower(){
		if (this.power.size()>0){
			double orginsPower = this.power.get(0);
			for (int I=1;I<this.power.size();I++){
				orginsPower*=this.power.get(I);
			}
			this.value = nSqrt(this.value,orginsPower);
			this.power.clear();
		}
	}
	public void nsqrt(double value){
		this.value = nSqrt(this.value, value);
		if (this.power.size()>0){
			if (value==this.power.get(this.power.size()-1)){
				this.power.remove(this.power.size()-1);
			}else{
				double orginsPower = this.power.get(0);
				for (int I=1;I<this.power.size();I++){
					orginsPower*=this.power.get(I);
				}
				if (orginsPower==value){
					this.power.clear();
				}
			}
		}
	}
	public Double[] getPower(){
		return this.power.toArray(new Double[this.power.size()]);
	}
	public double getOrginsPower(){
		double orginsPower = 1;
		if (this.power.size()>0){
			orginsPower = this.power.get(0);
			for (int I=1;I<this.power.size();I++){
				orginsPower*=this.power.get(I);
			}
		}
		return orginsPower;
	}
	public boolean hasPower(){
		return this.power.size()>0;
	}
	public String toString(){
		double orginsPower = 1;
		if (this.power.size()>0){
			orginsPower = this.power.get(0);
			for (int I=1;I<this.power.size();I++){
				orginsPower*=this.power.get(I);
			}
		}
		return this.value+" p"+orginsPower;
	}
}
